<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\ShopMoney
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property int $shop_id 店铺ID
 * @property string $pre_money 变更前余额
 * @property string $money 变更金额
 * @property string $after_money 变更后余额
 * @property string|null $remark 变更备注
 * @property int $type 变更类型:0=后台修改,1=订单金额,2=提现金额
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney query()
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney whereAfterMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney whereMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney wherePreMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney whereShopId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ShopMoney whereUserId($value)
 * @mixin \Eloquent
 */
class ShopMoney extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'shop_moneys';

    protected $fillable = [
        'type',
        'user_id',
        'shop_id',
        'pre_money',
        'money',
        'after_money',
        'remark',
    ];

    /**
     * 获取用户的
     * @param $user_id
     * @return array
     */
    public static function getList($user_id){
        $state = request()->input('state',0);
        $limit = request()->input('limit',10);
        $list = self::whereUserId($user_id)
            ->when($state,function ($query,$value){
                $query->where("money",$value==1?">":"<",0);
            })
            ->paginate($limit);
        $data['items'] = $list->items();
        $data['lastPage'] = $list->lastPage();
        $data['total'] = $list->total();
        return $data;
    }

}
